package com.example.controller;

import com.example.entity.Equipment;
import com.example.service.EquipmentService;
import com.example.service.ServiceImpl.EquipmentServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "器材管理模块",description = "器材的查询、添加、删除、保修、租借、回收、价格表")
@RequestMapping("/Equipment")
@Controller
public class EquipmentController {

    @Resource
    EquipmentService equipmentService = new EquipmentServiceImpl();

    @ApiOperation("器材分页查询")   //接口描述
    @RequestMapping(value = "/query-equipment", method = RequestMethod.GET)
    public String queryEquipment(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
                                  Model model){
        PageInfo<Equipment> equipmentPageInfo = equipmentService.queryEquipment(pageNum, pageSize);
        model.addAttribute("equipmentPageInfo", equipmentPageInfo);
        return "redirect:/page/equipment";
    }

    @ApiOperation("器材查询")   //接口描述
    @RequestMapping(value = "/select-equipment", method = RequestMethod.GET)
    public String selectEquipment(@RequestParam("equipmentId") String equipmentId){
        equipmentService.selectEquipment(Integer.parseInt(equipmentId));
        return "redirect:/page/equipment";
    }


    @ApiOperation("器材购置新增")   //接口描述
    @RequestMapping(value = "/add-equipment", method = RequestMethod.GET)
    public String addEquipment(@RequestParam("equipmentName")  String equipmentName, @RequestParam("equipmentState") String equipmentState, @RequestParam("equipmentCharges") String equipmentCharges){
        equipmentService.addEquipment(equipmentName, equipmentState, equipmentCharges);
        return "redirect:/page/equipment";
    }

    @ApiOperation("器材报废删除")   //接口描述
    @RequestMapping(value = "/delete-equipment", method = RequestMethod.GET)
    public String deleteEquipment(@RequestParam("equipmentId") int equipmentId){
        equipmentService.deleteEquipment(equipmentId);
        return "redirect:/page/equipment";
    }

    @ApiOperation("器材维护报修")   //接口描述
    @RequestMapping(value = "/repair-equipment", method = RequestMethod.GET)
    public String repairEquipment(@RequestParam("equipmentId") String equipmentId){
        equipmentService.repairEquipment(Integer.parseInt(equipmentId));
        return "redirect:/page/equipment";
    }

    @ApiOperation("器材租用")   //接口描述
    @RequestMapping(value = "/rent-equipment", method = RequestMethod.GET)
    public String rentEquipment(@RequestParam("equipmentId") String equipmentId){
        equipmentService.rentEquipment(Integer.parseInt(equipmentId));
        return "redirect:/page/equipment";
    }

    @ApiOperation("器材回收")   //接口描述
    @RequestMapping(value = "/recovery-equipment", method = RequestMethod.GET)
    public String recoveryEquipment(@RequestParam("equipmentId") String equipmentId){
        equipmentService.recoveryEquipment(Integer.parseInt(equipmentId));
        return "redirect:/page/equipment";
    }

    @ApiOperation("器材租用收费标准查询")   //接口描述
    @RequestMapping(value = "/charge-equipment", method = RequestMethod.GET)
    public String chargeEquipment(@RequestParam("equipmentId") String equipmentId){
        equipmentService.chargeEquipment(Integer.parseInt(equipmentId));
        return "redirect:/page/equipment";
    }

    @ApiOperation("器材租用时间")   //接口描述
    @RequestMapping(value = "/time", method = RequestMethod.GET)
    @ResponseBody
    public List<Equipment> time(){
        return equipmentService.selectTime();
    }
}
